include(ExternalProject)

set(OPENSSL_SOURCE_DIR ${PROJECT_BINARY_DIR}/third_party/openssl)

if (TARGET_PLATFORM STREQUAL "win")
    set(host mingw64 --cross-compile-prefix=x86_64-w64-mingw32-)
elseif (TARGET_PLATFORM STREQUAL "linux")
    set(host --cross-compile-prefix=x86_64-linux-gnu-)
endif ()

ExternalProject_Add(openssl
        URL https://gitee.com/madision/openssl/repository/archive/master.zip
        URL_MD5 ee2f4bcc01048843d00973154ff2566a
        DOWNLOAD_NAME openssl_3_5-dev.zip
        SOURCE_DIR ${OPENSSL_SOURCE_DIR}
        CONFIGURE_COMMAND cd ${OPENSSL_SOURCE_DIR} && ./config --prefix=${PROJECT_BINARY_DIR}/openssl_output no-asm no-shared ${host}
        BUILD_COMMAND cd ${OPENSSL_SOURCE_DIR} && make build_sw -j4
        INSTALL_COMMAND cd ${OPENSSL_SOURCE_DIR} && make install_sw)

ExternalProject_Add_StepTargets(
        openssl install
)

